<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>保险公司列表</title>
    
  <link href="style1.css" rel="stylesheet" type="text/css">
<script language="javascript" src="js/common.js"></script>
<script language="javascript" type="text/javascript">
	var rowlength; //每行多少个单元
	function init() {
		rowlength = document.getElementById('customerTable').rows[0].cells.length;
	}
	function choicename(name) {
		window.returnValue = name;
		window.close();
	}
	function choice(index) {
		window.returnValue = document.getElementById('customerTable').rows[index].cells[1].innerHTML;
		window.close();
	}
	function choiceAnonymous() {
		var len = customerTable.rows.length;
		var i;
		for (i = 1; i < len - 1; i++) {
			if (customerTable.rows[i].cells[0].innerHTML == "√") {
				choice(i);
				return;
			}
		}
		alert("请先选择公司");
	}
	function selectItem(customercode) {
		var len = customerTable.rows.length;
		var selectedNumber = -1;
		var i, length,index;
		for (i = 1; i < len - 1; i++) {
			if (customerTable.rows[i].cells[0].innerHTML == "√") {
				selectedNumber = i;
				break;
			}
		}
		for (i = 1; i < len - 1; i++) {
			if (customerTable.rows[i].cells[1].innerHTML == customercode) {
				index = i;
				break;
			}
		}
		if (selectedNumber==-1) { //第一次选择
			customerTable.rows[index].cells[0].innerHTML = "√";
			for(i=0; i<rowlength; i++)
				customerTable.rows[index].cells[i].style.backgroundColor = "#C1CDD8";
		} else if (selectedNumber==index) { //取消选择
			customerTable.rows[index].cells[0].innerHTML = "";
			for(i=0; i<rowlength; i++)
				customerTable.rows[index].cells[i].style.backgroundColor = "#fff7e5";
		} else if (selectedNumber!=index) { //取消上次选择并选择新的
			customerTable.rows[index].cells[0].innerHTML = "√";
			for(i=0; i<rowlength; i++)
				customerTable.rows[index].cells[i].style.backgroundColor = "#C1CDD8";
			customerTable.rows[selectedNumber].cells[0].innerHTML = "";
			for(i=0; i<rowlength; i++)
				customerTable.rows[selectedNumber].cells[i].style.backgroundColor = "#fff7e5";
		}
	}
</script>
</head>

<body onLoad="init()">
<table width="100%"  border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="30px" nowrap class="toolbar">&nbsp;</td>
    <td width="40px" nowrap class="toolbar" onClick="choiceAnonymous()"><a href="javascript:void(0)"  style="text-decoration:none"><img src="images/confirm.gif">确定</a></td>
    <td width="20px" nowrap class="toolbar">|</td>
    <td width="40px" nowrap class="toolbar" onClick="window.close()"><a href="javascript:void(0)"  style="text-decoration:none"><img src="images/cancel.gif">取消</a></td>
	<td align="center" valign="middle" nowrap class="toolbar">&nbsp;</td>
  </tr>
</table>
<table width="100%"  border="0" cellspacing="1" class="a1" id="customerTable" style="text-align: center">
  <tr>
    <td class="title1">选择</td>
    <td class="title1">公司编号</td>
    <td class="title1">公司名称</td>
    <td class="title1">公司电话</td>
  </tr>
  <c:forEach var="type" items="${requestScope.carType}">
	  <tr onClick="selectItem('${type.idType }')" onDblClick="choicename('${type.idType }')">
	    <td>&nbsp;</td>
	    <td>${type.idType }</td>
	    <td>${type.typename }</td>
	    <td>${type.bedding }</td>
	  </tr>  
  </c:forEach>
  
   <tr>
    <td class="title2"></td>
  </tr>
</table>
</body>
</html>
